(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/scripts/wall.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, 'bfc23+EwR1PhbyY8P9voFZP', 'wall', __filename);
// scripts/wall.js

'use strict';

// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        canGoTop: false
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad: function onLoad() {

        // 停止一个动作
        // this.node.stopAction(action);
        // 停止所有动作
        // this.node.stopAllActions();
        this.targetPointY = 0;
        this.fromTop = false;
    },
    runStop: function runStop() {
        this.node.stopAllActions();
    },
    runToPoint: function runToPoint(second, x, y, beginDestroy) {
        this.canGoTop = true;
        // var action = cc.moveTo(second, x, y);


        var finished = cc.callFunc(function () {
            this.canGoTop = false;
            this.fromTop = false;
            if (beginDestroy) {
                this.beginDestroy = false;
            }
            // console.log(2);
        }, this, 0);

        var myAction = cc.sequence(cc.moveTo(second, x, y), finished);

        // 执行动作
        this.node.runAction(myAction);
    },
    start: function start() {},
    update: function update(dt) {
        if (!this.canGoTop) {
            // console.log(1111);
            var count = 0;
            var goDieWalls = [];
            var destroyWallY = 0;
            for (var i = 0; i < this.game.walls.length; i++) {
                var wall = this.game.walls[i];
                var wallCanGoTop = wall.getComponent('wall').canGoTop;
                var targetPointY = wall.getComponent('wall').targetPointY;
                // console.log(wall.y);
                if (targetPointY === this.targetPointY && !wallCanGoTop) {
                    count++;
                    goDieWalls.push(wall);
                    // console.log(count);
                    if (count === 4) {
                        destroyWallY = targetPointY;
                        break;
                    }
                }
            }

            if (count === 4) {
                this.beginDestroy = true;
                for (var i = 0; i < goDieWalls.length; i++) {
                    var wall = goDieWalls[i];
                    var index = this.game.walls.indexOf(wall);
                    this.game.walls.splice(index, 1);
                    wall.destroy();
                }
                for (var i = 0; i < this.game.walls.length; i++) {
                    var wall = this.game.walls[i];
                    var targetPointY = wall.getComponent('wall').targetPointY;
                    if (destroyWallY + 330 > targetPointY + 330) {
                        var height = 380;
                        var wallActionSecond = 0.5;
                        // if (wall.x === this.node.x) {
                        height = targetPointY + 70;
                        if (height > 380) {
                            height = 380;
                        }
                        // }
                        // if (wall.getComponent('wall').canGoTop && !wall.getComponent('wall').fromTop) {
                        //     var otherHeight = 380;
                        //     var wallActionSecond = 1;
                        //     var currentHeight = wall.getComponent('wall').targetPointY;
                        //     for (var i = 0; i < this.game.walls.length; i++) {
                        //         var otherWall = this.game.walls[i];
                        //         var canGoTop = otherWall.getComponent('wall').canGoTop;
                        //         var targetPointY = otherWall.getComponent('wall').targetPointY;
                        //         // console.log(targetPointY);
                        //         if (wall.x === otherWall.x && targetPointY > currentHeight && !canGoTop) {
                        //             console.log(targetPointY);
                        //             //  console.log(currentHeight);
                        //             otherHeight = targetPointY > otherHeight ? otherHeight : targetPointY - 70;
                        //             currentHeight = targetPointY;
                        //         }
                        //     }
                        //     // console.log(height);
                        //     // console.log(currentHeight);
                        //     wallActionSecond = Math.abs(height - wall.y) * 0.0026;
                        //     wall.getComponent('wall').runStop();
                        //     wall.getComponent('wall').targetPointY = otherHeight;
                        //     wall.getComponent('wall').runToPoint(wallActionSecond, wall.x, otherHeight, this.beginDestroy);
                        // } else {
                        wallActionSecond = Math.abs(height - wall.y) * 0.0026;
                        wall.getComponent('wall').runStop();
                        wall.getComponent('wall').targetPointY = height;
                        wall.getComponent('wall').runToPoint(wallActionSecond, wall.x, height, this.beginDestroy);
                        // }

                    }
                }
            }
            // }
            //     }
        }
    }
});

cc._RF.pop();
        }
        if (CC_EDITOR) {
            __define(__module.exports, __require, __module);
        }
        else {
            cc.registerModuleFunc(__filename, function () {
                __define(__module.exports, __require, __module);
            });
        }
        })();
        //# sourceMappingURL=wall.js.map
        